package com.vis.view.ui
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	import mx.controls.Alert;
	
	public class App extends Sprite
	{
		//adding all the color constants for the vis
		public static const DEFAULT_BOUND:Rectangle=new Rectangle(0,0,500,500);
		public static const MAX_LABEL_LENGTH:uint = 15;
		public static const MAX_LEGEND_LENGTH:uint = 20;    
		public static const START_ANGLE_ZERO:Number = Math.PI;
		public static const START_ANGLE_NINTEY:Number = Math.PI / 2;
		protected var _appBounds:Rectangle;
		
		
		public function App(appBounds:Rectangle=null)
		{
			_appBounds =(appBounds==null)?App.DEFAULT_BOUND:appBounds;
			addEventListener(Event.ADDED_TO_STAGE, onStageAdd);
		}
		private function onStageAdd(evt:Event):void
		{
			
			removeEventListener(Event.ADDED_TO_STAGE, onStageAdd);
			initStage();
			init();
			onResize();
			stage.addEventListener(Event.RESIZE, onResize); 
		}
		
		private function onResize(evt:Event=null):void
		{
			_appBounds = (_appBounds==null)? new Rectangle(0, 0, stage.stageWidth, stage.stageHeight):_appBounds;
			resize(_appBounds.clone());
		}
		
		protected function initStage():void
		{
			if (!stage) {
				throw new Error(
					"Can't initialize Stage -- not yet added to stage");
			}
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
		}
		
		protected function init():void
		{
			
		}
		
		public function resize(bounds:Rectangle):void
		{
			
		}
		
		/**
		 * 
		 * @param text the original text
		 * @param maxSize the maximum size limit for text
		 * @return ellipsis added string.
		 * 
		 */		
		public static function addEllipsis(text:String, maxSize:uint):String{
			if (text != null && text.length > maxSize){	
				return (text.substr(0, maxSize - 3)) + "...";
			} else {
				return text;
			}
		}
	}
}